package com.zhwl.manage.controller;

import com.zhwl.common.annotation.Log;
import com.zhwl.common.core.controller.BaseController;
import com.zhwl.common.core.domain.AjaxResult;
import com.zhwl.common.core.page.TableDataInfo;
import com.zhwl.common.enums.BusinessType;
import com.zhwl.common.utils.poi.ExcelUtil;
import com.zhwl.manage.domain.Variables;
import com.zhwl.manage.service.IVariablesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 变量管理Controller
 * 
 * @author mobin
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/manage/variables")
public class VariablesController extends BaseController
{
    @Autowired
    private IVariablesService variablesService;

    /**
     * 查询变量管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Variables variables)
    {
        startPage();
        List<Variables> list = variablesService.selectVariablesList(variables);
        return getDataTable(list);
    }

    /**
     * 导出变量管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:variables:export')")
    @Log(title = "变量管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Variables variables)
    {
        List<Variables> list = variablesService.selectVariablesList(variables);
        ExcelUtil<Variables> util = new ExcelUtil<Variables>(Variables.class);
        util.exportExcel(response, list, "变量管理数据");
    }

    /**
     * 获取变量管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:variables:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(variablesService.selectVariablesById(id));
    }

    /**
     * 新增变量管理
     */
    @PreAuthorize("@ss.hasPermi('manage:variables:add')")
    @Log(title = "变量管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Variables variables)
    {
        return toAjax(variablesService.insertVariables(variables));
    }

    /**
     * 修改变量管理
     */
    @PreAuthorize("@ss.hasPermi('manage:variables:edit')")
    @Log(title = "变量管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Variables variables)
    {
        return toAjax(variablesService.updateVariables(variables));
    }

    /**
     * 删除变量管理
     */
    @PreAuthorize("@ss.hasPermi('manage:variables:remove')")
    @Log(title = "变量管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(variablesService.deleteVariablesByIds(ids));
    }
}
